let arr = ['苹果','苹果','苹果','香蕉','香蕉','橘子','橘子','橘子','草莓','火龙果','火龙果']

let result=[];

arr.forEach(item=>{
  let obj={name:item,num:1};
  let i=result.findIndex(ele=>ele.name==item);
  i !==-1 ? result[i].num+=1:result.push(obj)
  // console.log("********************")
  // console.log(result)
  // console.log(i)
})

result.sort((a,b)=>a.num-b.num)

console.log(Object.keys(result))

let sum=0;

for(let index=0,len=result.length;index<len;index++){
  sum+=result[index].num;

  if(sum>5){
    break
  }else{
    result.splice(index,1)
    index--
  }
}
console.log(result)




